package bai.myworld.exception;

import lombok.Getter;

@Getter
public enum ErrorCode {

    // ===== JWT 相关错误 =====
    TOKEN_EXPIRED(401, "A0421", "Token已过期"),
    TOKEN_TAMPERED(401, "A0422", "Token被篡改"),
    TOKEN_MISSING(401, "A0423", "Token缺失"),
    TOKEN_INVALID(401, "A0424", "Token无效"),
    REFRESH_TOKEN_INVALID(40103, "A040103","refreshToken无效"),

    // ===== 4xx 用户客户端错误 =====
    BAD_REQUEST(400, "A0400", "请求参数错误"),
    USERNAME_EXISTS(400, "A0410", "用户名已存在"),
    UNAUTHORIZED(401, "A0401", "未授权访问"),
    FORBIDDEN(403, "A0403", "权限不足"),
    USER_NOT_FOUND(401, "A0411", "用户名不存在"),       // 和密码错误分开提示更安全
    PASSWORD_ERROR(401, "A0412", "密码错误"),          // 不提示"用户名或密码错误"这种模糊信息
    ACCOUNT_LOCKED(403, "A0413", "账户已锁定"),        // 多次失败后锁定
    LOGIN_LIMIT(429, "A0414", "登录尝试过多，请稍后再试"), // 限流专用
    CAPTCHA_ERROR(400, "A0415", "验证码错误"),         // 如果需要验证码功能
    ACCOUNT_DISABLED(403, "A0416", "账户已禁用"),       // 管理员手动禁用

    // ===== 5xx 服务端错误 =====
    INTERNAL_ERROR(500, "B0500", "系统内部错误"),
    SERVICE_UNAVAILABLE(503, "B0503", "服务不可用"),

    // ===== 商城模块错误码（4xx客户端错误）=====
    PRODUCT_NOT_FOUND(404, "A0440", "商品不存在或已下架"),
    INSUFFICIENT_STOCK(409, "A0441", "库存不足"),
    SHOP_CLOSED(403, "A0442", "店铺已歇业"),
    INVALID_PRODUCT_PRICE(400, "A0443", "商品价格不合法"),
    COUPON_EXPIRED(400, "A0444", "优惠券已过期"),
    COUPON_LIMIT_EXCEEDED(400, "A0445", "优惠券使用超限"),
    CART_OPERATION_FAILED(400, "A0446", "购物车操作失败"),
    ORDER_STATUS_CONFLICT(409, "A0447", "订单状态冲突"),
    ADDRESS_VALIDATION_FAILED(400, "A0448", "收货地址校验失败"),
    PAYMENT_VERIFY_FAILED(402, "A0449", "支付验证失败"),
    PURCHASE_LIMIT_EXCEEDED(429, "A0450", "超出购买限制"),

    // ===== 商城服务端错误（5xx）=====
    PRODUCT_SYNC_FAILED(500, "B0510", "商品信息同步失败"),
    ORDER_GENERATE_FAILED(500, "B0511", "订单生成异常"),
    INVENTORY_LOCK_FAILED(503, "B0512", "库存锁定失败");



    private final int httpStatus;  // HTTP状态码
    private final String code;     // 业务错误码（A0400/B0500格式）
    private final String defaultMsg; // 默认错误信息

    // 构造器
    ErrorCode(int httpStatus, String code, String defaultMsg) {
        this.httpStatus = httpStatus;
        this.code = code;
        this.defaultMsg = defaultMsg;
    }
}
